package com.exp06.Listener;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebListener;

import java.util.Date;

@WebListener
public class MyServletContextListener implements ServletContextListener , ServletContextAttributeListener {
    private ServletContext servletContext=null;
    public void contextInitialized(ServletContextEvent sce){
        servletContext = sce.getServletContext();
        servletContext.log("应用程序启动"+new Date());
    }

    public void contextDestroyed(ServletContextEvent sce) {
        servletContext = sce.getServletContext();
        servletContext.log("应用程序关闭"+new Date());
    }

    public void attributeAdded(ServletContextAttributeEvent sce){
        servletContext = sce.getServletContext();
        servletContext.log("添加一个属性"+sce.getName()+":"+sce.getValue());
    }

    public void attributeRemoved(ServletContextAttributeEvent sce){
        servletContext = sce.getServletContext();
        servletContext.log("删除了一个属性"+sce.getName() + ":"+sce.getValue());
    }

    public void attributeReplaced(ServletContextAttributeEvent sce) {
        servletContext = sce.getServletContext();
        servletContext.log("替换了一个属性"+sce.getName() + ":"+sce.getValue());
    }
}
